package com.rerun.common.email;

import com.rerun.entity.vo.InterviewTemplateParam;
import com.rerun.entity.vo.ResumeTemplateParam;
import com.rerun.entity.vo.WorkExp;
import com.rerun.common.util.CommonUtil;
import com.rerun.entity.EduBackground;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 邮件 Html 模板.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /10/9 14:43
 */
public class HtmlMailTemplate implements Serializable {
    private static final String INTERVIEW_CONTENT = "你的简历已经通过筛选，很高兴邀请你参加面试。";
    private static final String NULL_VAL = " 无 ";
    private static final long serialVersionUID = 3385320729862605181L;

    /**
     * 邮件面试邀请函模板.
     *
     * @param param the param
     * @return the string
     */
    public static String interviewTemplate(InterviewTemplateParam param) {

        StringBuilder html = new StringBuilder();
        html.append("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><meta charset=\"utf-8\" /><title></title><style type=\"text/css\">");
        html.append("*{margin:0;padding:0}body{font-family:\"微软雅黑\";color:#323232;font-size:14px}a{text-decoration:none}li{list-style:none}.clear::after{content:\".\";height:0;display:block;visibility:hidden;clear:both}.all{margin:45px auto;width:680px;height:920px;position:relative;background:url(cid:mailbg01.png) no-repeat}.con{width:580px;background:#fff;border-radius:3%;position:absolute;top:120px;left:50px}.all_con{margin-left:20px;position:relative}.one{margin:40px 0 10px 0}.two{margin-bottom:30px}.three{width:560px}.three li{line-height:27px}.userName{color:#00b289;font-weight:600;font-size:22px;}.three li span{font-weight:700}.four{color:#fc9d08}.five{margin:40px 0 60px 0;width:374px}.six{background:rgba(212,201,183,.75);width:360px;padding:5px;margin-bottom:25px}.six{margin-top:20px;}.six ul li{line-height:20px;font-size:12px}.sev{width:100px;height:130px;color:#a0a0;position:absolute;right:10px;bottom:0;}.sev img{width:100%;}.tou{width:110px;height:110px;position:absolute;right:-5px;top:-45px;background:url(cid:mailbg02.png)}.hh b{width:13%;display:inline-block;float:left}.hh p{width:87%;display:inline-block;float:left}.five b{width:84%;display:inline-block;float:right}.four{display:inline-block}.aa{-webkit-transform:rotate(43deg);-moz-transform:rotate(43deg);filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);top:-12px;font-size:16px;color:#fff}.hh1 b{width:8%;display:inline-block;float:left}.hh1 span{width:70%;display:inline-block;float:left;color:#323232}.yaoqing{transform:rotate(45deg);width:110px;height:110px;position:absolute;right:-7px;top:-12px;z-index:999;color:#FFF;font-size:16px}");
        html.append("</style>");
        html.append("</head><body><div class=\"all\"><div class=\"con\"><div class=\"all_con\"><p class=\"one\"><span class=\"userName\">");
        html.append(param.getReceiverName());
        html.append("</span>,您好!</p>");
        html.append("<p class=\"two\">");
        html.append(INTERVIEW_CONTENT);
        html.append("</p>");
        html.append("<ul class=\"three\"><li class=\"hh\"><b>园所名称：</b><span>");
        html.append(param.getParkName());
        html.append("</span></li>");
        html.append("<li class=\"hh\"><b>面试职位：</b><span>");
        html.append(param.getJobName());
        html.append("</span></li>");
        html.append("<li class=\"hh clear\"><b>面试时间：</b><p><span>");
        html.append(param.getInterviewTime());
        html.append("</span></p></li>");
        html.append("<li class=\"hh clear\"><b>面试地点：</b><p>");
        html.append(param.getAddress());
        html.append("</p></li>");
        html.append("<li class=\"hh\"><b>联系人：</b>");
        html.append(param.getHrName());
        html.append("</li>");
        html.append("<li class=\"hh\"><b>联系电话：</b>");
        html.append(param.getPhone());
        html.append("</li>");
        String remark = param.getRemark();
        if (!StringUtils.isEmpty(remark)) {
            html.append("<p class=\"five\"></b>备注：</b><b class=\"four\">");
            html.append(remark);
            html.append("</b></p>");
        }
        html.append("<div class=\"six\"><ul><li class=\"list clear\">任何疑问，请拨打客服电话 400-1826-836 </li>");
        html.append("<li class=\"list clear\">我们保证仅向您发送关于职场相关的电子邮件。</li>");
        html.append("<li class=\"list clear\">我们保证不会主动向外界泄露您的个人隐私。</li>");
        html.append("</ul></div><div class=\"sev\"/><img src=\"cid:qrcode.png\" alt=\"\"></div><p class=\"yaoqing\">面试邀请</p><div class=\"tou\"/></div></div></div></div></body></html>");
        return html.toString();
    }


    /**
     * Receive resume template string.
     *
     * @param param the param
     * @return the string
     */
    public static String receiveResumeTemplate(ResumeTemplateParam param) {
        StringBuilder html = new StringBuilder();
        html.append("<html><head><meta name=\"viewport\" content=\"width=640, initial-scale=0\" /><meta charset=\"utf-8\" /><title></title><style type=\"text/css\">");
        html.append("*{margin:0;padding:0}body{font-family:\"微软雅黑\";color:#323232;font-size:14px}a{text-decoration:none}li{list-style:none}.clear::after{content:\".\";height:0;display:block;visibility:hidden;clear:both}.all{background:url(../img/bg01.png) no-repeat;margin:21px auto;width:640px;position:relative}.all p{margin-top:5px}.yue_con{width:100%;background:#e8fdf8;border-radius:2.5%;position:absolute;top:50px;border:1px solid #e8dcdc;border-top:none;border-bottom:none}.name{margin:10px 10px 20px 10px;margin-top:33px}.name_le{float:left;width:15%;border-radius:50%;margin-left:8px}.name_ri{float:right;width:81%}.zhiwei img{margin-right:10px}.zhiwei p{margin:10px 10px 20px 40px}.jingli ul li{margin:5px 0 10px 40px}.scl{margin-left:-10px}.jingli p{margin-left:21px}.xingbie{margin-left:20px;color:#769221}.zhuanye b{width:13%;display:inline-block;float:left}.zhuanye span{width:87%;display:inline-block;font-size:14px}.ban{margin:0 45px}.zhao{margin:0 37px}.neirong b{width:4%;display:inline-block;float:left}.neirong span{width:87%;display:inline-block;font-size:14px}.xue{color:#00b289;font-size:22px;font-weight:600}.biaodian{width:8px;height:8px;margin-top:5px;display:block;float:left;background:#98ead8;border-radius:50%;margin-right:10px}header{width:100%;background:#98ead8;border-radius:20px 20px 0 0;line-height:60px;color:#323232;text-align:center;font-size:18px}.yueduimg{width:90px;height:33px;display:block}.yg{width:100px;height:33px;background-color:#98ead8;border-radius:0 0 20px 0;color:#323232;text-align:center;line-height:33px}footer{width:100%;background:#98ead8;height:44px;border-radius:0 0 20px 20px;line-height:60px}.yueduqian{width:64px;height:64px}.mob{margin-right:20px}.ming{font-size:x-large}.job{color:#666}");
        html.append("</style>");
        html.append("</head><body><div class=\"all\"><p class=\"yuekai\">您收到一份来自<span class=\"xue\">&nbsp;");
        String resumeName = param.getName();
        html.append(resumeName);
        html.append("&nbsp;</span>的面试&nbsp;<b>");
        html.append(param.getJobName());
        html.append("</b>&nbsp;的申请：</p>");
        String sex = param.getSex();
        html.append("<div class=\"yue_con\"><header>简历预览</header><div class=\"name clear\"><div class=\"name_le\"><p class=\"yueduqian\"><img src=\"cid:");
        if ("男".equals(sex)) {
            html.append("male.png");
        }
        if ("女".equals(sex)) {
            html.append("female.png");
        }
        html.append("\" /></p></div><div class=\"name_ri\"><p><b class=\"ming\">");
        html.append(resumeName);
        html.append("</b><span class=\"xingbie\">");
        html.append(sex);
        html.append("</span></p><p><b><span>");
        html.append(param.getBirthDay());
        html.append("</span>/<span>");
        html.append(param.getExperience());
        html.append("</span>/<span>");
        html.append(param.getHighestEdu());
        String livingCity=param.getLivingCity();
        if (StringUtils.isNotEmpty(livingCity)){
            html.append("</span>/<span>");
            html.append(livingCity);
        }

        html.append("</span></b></p><p><b>手机：</b>&nbsp;&nbsp;<span class=\"mob\">");
        html.append(param.getPhone());
        html.append("</span> <b>邮箱：</b>&nbsp;&nbsp;<span>");
        html.append(param.getEmail());
        html.append("</span></p></div></div>");

        html.append("<div class=\"zhiwei\"><span class=\"yueduimg yg\"><b>期望职位</b></span>");

        String hopeJobType=param.getJobType();
        String  hopeType=StringUtils.isNotEmpty(hopeJobType)? hopeJobType: NULL_VAL;

        html.append("<p class=\"zhuanye clear\"><b>期望职位：</b><span>");
        html.append(hopeType);
        html.append("</span></p>");


        String hopePay=param.getHopePay();
        String hopeJobPay=StringUtils.isNotEmpty(hopePay)?hopePay:NULL_VAL;

        html.append("<p><b>期望薪资：<span>");
        html.append(hopeJobPay);
        html.append("</span></b></p></div>");

        String skill =param.getSkillName();
        String skillName=StringUtils.isNotEmpty(skill)?skill:NULL_VAL;

        html.append("<div class=\"zhiwei\"><span class=\"yueduimg yg\"><b>技能优势</b></span>");
        html.append("<p class=\"zhuanye clear\"><b>专业技能：</b><span>");
        html.append(skillName);
        html.append("</span></p></div>");


        html.append("<div class=\"zhiwei\"><span class=\"yueduimg yg\"><b>教育经历</b></span>");
        List<EduBackground> eduBackgrounds = param.getEduBackgroundList();
        if (!eduBackgrounds.isEmpty()) {
            for (EduBackground eduBackground : eduBackgrounds) {
                if (Objects.nonNull(eduBackground)){
                    String schoolName=eduBackground.getSchoolName();
                    if (StringUtils.isNotEmpty(schoolName)){
                        html.append("<p><b>");
                        html.append(schoolName);
                        html.append("</b><b class=\"zhao\">");
                        String m=eduBackground.getMajor();
                        String major=m!=null? m:"";
                        html.append(major);
                        html.append("</b><b>");
                        html.append(CommonUtil.formatDate(eduBackground.getStartDate(), "yyyy-MM-dd"));
                        html.append(" - ");
                        html.append(CommonUtil.formatDate(eduBackground.getEndDate(), "yyyy-MM-dd"));
                        html.append("</b></p>");
                    }

                }
            }
        }
        html.append("</div>");
        html.append("<div class=\"zhiwei jingli\"><span class=\"yueduimg yg\"><b>工作经历</b></span>");
        List<WorkExp> workExps = param.getWorkExpList();
        if (!workExps.isEmpty()) {
            for (WorkExp exp : workExps) {
                if (Objects.nonNull(exp)){
                    html.append("<div class=\"express\"><p class=\"clear\"><b><span class=\"biaodian\"></span></b><b>");
                    html.append(exp.getCompanyName());
                    html.append("</b><b class=\"ban\">");
                    String expJob =exp.getJob();
                    String expJ=StringUtils.isNotEmpty(expJob)?expJob:"";
                    html.append(expJ);
                    html.append("</b><b>");
                    html.append(CommonUtil.formatDate(exp.getStartDate(), "yyyy-MM-dd"));
                    html.append(" - ");
                    html.append(CommonUtil.formatDate(exp.getEndDate(), "yyyy-MM-dd"));
                    html.append("</b></p><ul><li class=\"job\">工作内容</li><li class=\"neirong clear\"><span>");
                    html.append(exp.getWorkDescribe());
                    html.append("</span></li></ul></div>");
                }
            }

        }
        html.append("</div>");
        html.append("</div>");
        html.append("<div class=\"log\" style=\"width: 70%;margin: 0 129.5px;\"><img src=\"cid:ads01.png\" alt=\"\" style=\"width: 85%;\"></div><footer></footer></div></div></body></html>");
        return html.toString();
    }
}
